<?php
// +----------------------------------------------------------------------
// | 奇乐中介担保交易系统 免费版 2019
// +----------------------------------------------------------------------
// | 官方网址：http://www.qilecms.com   
// +----------------------------------------------------------------------
// | 产品文档：http://www.qilecms.com/doc
// +----------------------------------------------------------------------
// | 开发作者:奇乐CMS
// +----------------------------------------------------------------------
// | 版权说明：这不是一个自由软件！本产品仅限个人使用，但请务必保留底部版权，以免产生不必要的纠纷,
// | 您只能在不用于商业目的的前提下对程序代码进行修改和使用，
// | 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
// +----------------------------------------------------------------------
namespace app\user\controller;
use think\Db;
class Home  extends Base
{
    public function initialize()
    {
       parent::initialize();
        $param = $this->request->param();
      if(!is_numeric($param['uid'])){
        return $this->error('当前用户不存在！');
      }

      $map[]    = ['uid','=',intval($param['uid'])];
      $map[]    = ['status','IN',[1]];

      $userinfo   = model('user')->infoData($map);

      if(empty($userinfo)){
        return $this->error('当前用户不存在！');
      }   
      $this->assign('empty','<span class="empty">暂无内容</span>');
      $this->assign('userinfo',$userinfo);
    }
    public function index()
    {
      $param = $this->request->param();

      if(!is_numeric($param['uid'])){
        return $this->error('该用户不存在！');
      }
       $uid = $param['uid'];
        // 别人评价我的
       $where['seller_uid'] = $uid;
       $lists = model('guarantee')->listPageData($where,'','',10);
       $list = $lists->toArray()['data'];

       $userlist = $this->getCache('user','uid');
       foreach($list as $k=>$v){
          $list[$k]['buyer_info']['avatar']  = $userlist[$v['buyer_uid']]['avatar'];
       }
       $page = $lists->render();
       $this->assign('list',$list);

       
      // 模板变量赋值
      $this->assign('list', $list);
      $this->assign('page', $page);
      return $this->fetch();

    }


// 卖家的评价
    public function sellerEvaluate()
    {
    $param = $this->request->param();
      if(!is_numeric($param['uid'])){
        return $this->error('该用户不存在！');
      }
       $uid = $param['uid'];
       $urlParam['page'] = $param['page'];
      //我评价别人的
       $where['buyer_uid'] = $uid;
       $lists = model('guarantee')->listPageData($where,'','',"10,true,['query'=>request()->param()]");
       $userlist = $this->getCache('user','uid');

       $list = $lists->toArray()['data'];
       $page = $lists->render();
       foreach($list as $k=>$v){
          $list[$k]['seller_info']['avatar']  = $userlist[$v['seller_uid']]['avatar'];
       }
       $this->assign('list',$list);
       $this->assign('page', $page);

      return $this->fetch();
    }
  public function info()
  {

      $param = $this->request->param();
      if(!is_numeric($param['uid'])){
        return $this->error('该用户不存在！');
      }
       $uid = $param['uid'];
//我发布的交易信息
      $map[] = ['uid','=',$uid];
      $map[] =['status','>=',1];
      $lists = model('guarantee_info')->listPageData($map,'','',10);  
      $page = $lists->render();
      $list = $lists->toArray()['data'];
      $this->assign('list',$list);
       $this->assign('page', $page);
      return $this->fetch();

  }
}
